# -*- coding:utf-8 -*-
import os,sys,json

from tornado.web import Application, RequestHandler, url
from tornado.ioloop import IOLoop
from tornado.httpserver import HTTPServer
from tornado.options import options,define
import tornado.options

from bin import ManDB,ManRedis
from bin import manapp
from bin import imgs
from bin import Man_QRBarCode
from bin import Man_Language
from bin import Man_Qiyeinfo
from bin import Man_Shopinfo
from bin import Man_Toutiao
from bin import Man_Autocreate
from bin import Man_Crypto

define("port", default=8888, type=int)

class IndexHandler(RequestHandler):

   def set_default_headers(self):
        # 第二种响应头设置方式
        print("---------> 响应头set_default_headers()执行")
        self.set_header("Content-type", "application/json; charset=utf-8")
        self.set_header("Mange", "ManGe")
   def get(self):
        # 第一种操作响应头的方式：
        # self.set_header("Content-type", "application/json")
        print("---------->get方法执行")
        datas = {'ManAPI':'中台微服务接口','版本':'v0.2'}
        self.write(json.dumps(datas).encode('utf-8').decode("unicode-escape"))
        self.set_header("Content-type", "application/json; charset=utf-8")



class Quit(RequestHandler):
    def get(self):
        os.exit()


class MainHandler(RequestHandler):

    def get(self,id):
        if id == "a":
            appid = self.get_argument("appid")
            print(appid)
            appkey = self.get_argument("appkey")
            print(appkey)
            self.write("Hello World"+id)
        else:
            self.write("NONO")

    

URL_PATH = [
            (r"/", IndexHandler),
            url(r"/quit", Quit, name="Quit"),#退出
            url(r"/testapp", manapp.TestAPP, name="testapp"),#测试接口
            url(r"/sendsms", manapp.ManSMS, name="ManSMS"),#短信验证码发送
            url(r"/verifysms", manapp.Verify_SMS, name="Verify_SMS"),#短信验证码验证
            url(r"/manfenci", manapp.ManTag, name="ManTag"),#分词
            url(r"/updataimg", imgs.UpdataIMG, name="UpdataIMG"),#上传图片
            url(r"/posttest", manapp.POSTtest, name="POSTtest"),#POST 接口测试
            url(r"/manbarcode", Man_QRBarCode.ManBarCode, name="ManBarCode"),#生成条形码
            url(r"/manqrcode", Man_QRBarCode.ManQRCode, name="ManQRCode"),#生成二维码
            url(r"/manfanyi", Man_Language.Manfanyi, name="Manfanyi"),#英汉翻译接口
            url(r"/manpingyin", Man_Language.Manpingyin, name="Manpingyin"),#汉语转拼音
            url(r"/getgushici", Man_Language.GetGSC, name="GetGSC"),#获取古诗词
            url(r"/getgscauthor", Man_Language.GetGSC_Author, name="GetGSC_Author"),#获取古诗词作者信息

            url(r"/scxyquery/([^/]+)", Man_Qiyeinfo.SCQY_CX, name="SCQY_CX"),#四川事业单位查询  SCQY_CX /scxyquery/([^/]+)

            url(r"/getscsczt", Man_Qiyeinfo.Get_SCSCZT, name="Get_SCSCZT"),#四川市场主体查询  Get_SCSCZT
            url(r"/getscjgqt", Man_Qiyeinfo.Get_SCJGQT, name="Get_SCJGQT"),#四川机关群体查询  Get_SCJGQT
            url(r"/getscshzz", Man_Qiyeinfo.Get_SCSHZZ, name="Get_SCSHZZ"),#四川社会组织查询  Get_SCSHZZ

            url(r"/createsfz/([^/]+)", Man_Autocreate.Create_sfz, name="Create_sfz"),#随机生成身份证接口  Create_sfz  /createsfz/([^/]+)
            url(r"/sfzverify/([^/]+)", Man_Autocreate.SFZ_verify, name="SFZ_verify"),#身份证验证接口  SFZ_verify  /verifytype/([^/]+)
            url(r"/getsfzinfo", Man_Autocreate.Get_sfzinfo, name="Get_sfzinfo"),#获取身份证信息接口  Get_sfzinfo  /getsfzinfo

            url(r"/createphonenumber", Man_Autocreate.Create_PhoneNumber, name="Create_PhoneNumber"),#自动生成电话号码  Create_PhoneNumber  /createphonenumber
            url(r"/getphonenumberinfo", Man_Autocreate.Get_PhoneNumberinfo, name="Get_PhoneNumberinfo"),#电话号码归属地查询  Get_PhoneNumberinfo  /getphonenumberinfo 
            url(r"/strtomd5", Man_Crypto.StrToMD5, name="StrToMD5"),#字符串MD5加密 StrToMD5 /strtomd5
            url(r"/setuuid", Man_Crypto.CUUID, name="CUUID"),#随机生成uuid CUUID /setuuid
            url(r"/creatqq", Man_Autocreate.Get_QQnumber, name="Get_QQnumber"),#自动生成QQ号码 Get_QQnumber /creatqq
            url(r"/id/([^/]+)",MainHandler),
            #图片压缩接口
            #
           ]




if __name__ == "__main__":
    ManRedis.start_man_api("v0.3")
    ManRedis.start_redis()#启动 Redis
    app = Application(URL_PATH)
    tornado.options.parse_command_line()
    http_server = HTTPServer(app)
    http_server.listen(8888)
    IOLoop.current().start()

